package com.fms.data.messaging;

import junit.framework.TestCase;

import org.jmock.Expectations;
import org.jmock.Mockery;

import com.fms.data.messaging.data.IEmailDataFiller;
import com.fms.data.messaging.data.SingletonEmailDataRepo;
import com.fms.model.messaging.domain.IEmailData;

public class SingleEmailDataServiceTest extends TestCase
{
	private Mockery mock;

	
	public void setUp()
	{
		mock = new Mockery();
	}
	
	
	public void tearDown()
	{
		mock.assertIsSatisfied();
	}
	
	
	public void testCheckLoadCalledOnlyOnce()
	{
		final IEmailData data = mock.mock(IEmailData.class);
		final IEmailDataFiller repo = mock.mock(IEmailDataFiller.class);
		
		mock.checking(new Expectations()
		{{
			oneOf(repo).fill(with(data));
		}});
		
		SingletonEmailDataRepo s = new SingletonEmailDataRepo(data, repo);
		
		assertTrue(s.load() == data);
		assertTrue(s.load() == data);
		assertTrue(s.load() == data);
		assertTrue(s.load() == data);
		
		
		
	}
	
	public void testSavePassedToRepo()
	{
		final IEmailData data = mock.mock(IEmailData.class);
		final IEmailDataFiller repo = mock.mock(IEmailDataFiller.class);
		
		mock.checking(new Expectations()
		{{
			oneOf(repo).fill(with(data));
			oneOf(repo).save(with(data));
		}});
		
		SingletonEmailDataRepo s = new SingletonEmailDataRepo(data, repo);
		
		assertTrue(s.load() == data);
		s.save(data);
		
		
		
	}
}
